﻿using HardcoreGame.Common.CustomSets;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Items.Weapons.Sets.Mushroom
{
    public class ShroomiteTripeater : ModItem
    {
        public override void SetStaticDefaults()
        {
            CustomItemSets.MushroomWeapon[Type] = true;
        }
        public override void SetDefaults()
        {
            Item.damage = 64;
            Item.DamageType = DamageClass.Ranged;
            Item.width = 20;
            Item.height = 20;
            Item.useAnimation = 15;
            Item.useTime = 5;
            Item.reuseDelay = 15;
            Item.useStyle = 5;
            Item.noMelee = true;
            Item.knockBack = 2;
            Item.value = 375000;
            Item.rare = 8;
            Item.UseSound = SoundID.Item5;
            Item.autoReuse = true;
            Item.shoot = 1;
            Item.shootSpeed = 8f;
            Item.useAmmo = AmmoID.Arrow;
        }

        public override bool CanConsumeAmmo(Item ammo, Player player)
        {
            return !(player.itemAnimation < Item.useAnimation - 2);
        }

        public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
        {
            if (type == ProjectileID.WoodenArrowFriendly)
            {
                Vector2 perturbedvelocity = new Vector2(velocity.X, velocity.Y).RotatedByRandom(MathHelper.ToRadians(6));
                velocity.X = perturbedvelocity.X;
                velocity.Y = perturbedvelocity.Y;
                int arrow = Projectile.NewProjectile(source, position.X, position.Y, velocity.X, velocity.Y, Item.shoot, damage, knockback, player.whoAmI);
                Main.projectile[arrow].noDropItem = true;
                return false;
            }
            else
            {
                Vector2 perturbedvelocity = new Vector2(velocity.X, velocity.Y).RotatedByRandom(MathHelper.ToRadians(6));
                velocity.X = perturbedvelocity.X;
                velocity.Y = perturbedvelocity.Y;
                return true;
            }
        }

        public override void AddRecipes()
        {
            CreateRecipe()
            .AddIngredient(ItemID.ShroomiteBar, 12)
            .AddTile(TileID.MythrilAnvil)
            .Register();
        }

        public override Vector2? HoldoutOffset()
        {
            return new Vector2(-2, 0);
        }
    }
}